
tick	 .byte  0
sekunda1 .byte  0
sekunda2 .byte  0
minuta   .byte  0

clk_tick

	inc tick
	lda tick
	cmp #50
	bne clk1
	
	inc sekunda1
	lda #0
	sta tick
clk1	
	lda sekunda1
	cmp #10
	bne clk2
	
	lda #0
	sta sekunda1
	inc sekunda2
clk2	
	lda sekunda2
	cmp #6
	bne clk3
	
	lda #0
	sta sekunda2
	inc minuta
	
clk3	
	lda jbox
	bne clk5
	
	lda minuta
	cmp #10
	bne clk4

	jsr clk_reset
	jmp clk4

clk5	lda minuta 
jboxt	cmp #3			; jukebox timer
	bne clk4
	jsr zakplus
	
	lda $d011
	eor #16
	sta $d011
	jsr reset_sid
	jsr tuneload
	jsr init

	lda $d011
	eor #16
	sta $d011


clk4

	rts

clk_reset

	lda #0
	sta tick
	sta sekunda1
	sta sekunda2
	sta minuta
	rts

;186 = 0
	
clock_rysuj

	lda jboxt+1
	cmp #1
	bne zz10
	lda #15
	jmp zz20

zz10	cmp #2
	bne zz11
	lda #12
	jmp zz20


zz11	lda #11	
zz20	sta $d02c	; jbox
	
	lda #255
	sta $d005
	sta $d007
	sta $d009

	sta $d00b	 ; jbox ixon

	lda #140
	sta $d004
	lda #180
	sta $d006
	lda #204
	sta $d008

	lda #240	; jbox
	sta $d00a

	lda #186
	clc
	adc minuta
	sta $6c00-6

	lda #186
	clc
	adc sekunda2
	sta $6c00-5

	lda #186
	clc
	adc sekunda1
	sta $6c00-4


	lda jbox
	beq k3
	
	lda #ijbox
	jmp k4
	
k3	lda #imbox
k4	sta $6c00-3

	rts

jbox .byte 0

jboxtoggle
	lda jbox
	eor #1
	sta jbox
	rts

jbox1
	lda #1
	sta jboxt+1
	rts

jbox2
	lda #2
	sta jboxt+1
	rts

jbox3
	lda #3
	sta jboxt+1
	rts

